package com.vipheyue.bigcompany.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.EditText;

/**
 * Created by admin on 06/24/2015.
 */
public class CustomEditText extends EditText {

    private Rect mRect;
    boolean isFocus =false;
    private Paint mPaint;
    int widthMsSize;
    int heightMsSize ;
    // we need this constructor for LayoutInflater
    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(3);
    }

    protected void onMeasure(final int widthMeasureSpec,
                             final int heightMeasureSpec) {
        // Extract the Ms (MesaureSpec) parameters

        widthMsSize = MeasureSpec.getSize(widthMeasureSpec);

        heightMsSize = MeasureSpec.getSize(heightMeasureSpec);

        // Satisfy contract by calling setMeasuredDimension
        setMeasuredDimension(widthMsSize,
                heightMsSize);
    }

    protected void onDraw(Canvas canvas) {

        if (isFocus) {
            mPaint.setColor(Color.parseColor("#D89300"));
        }else {
            mPaint.setColor(Color.parseColor("#D2D2D2"));
        }

        canvas.drawLine(7, heightMsSize-20, widthMsSize-7, heightMsSize-20, mPaint); //draw underline

        canvas.drawLine(8, heightMsSize-20,8, heightMsSize-28, mPaint); //draw left corner

        canvas.drawLine(widthMsSize-9,  heightMsSize-20,widthMsSize-9,  heightMsSize-28, mPaint); //draw right corner

        super.onDraw(canvas);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction,
                                  Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        if (focused) {
            isFocus = true;
        } else {
            isFocus = false;
        }
    }
}